home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / Developer University / DU Projects / Calc / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  3.6 KB  |  144 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef FRAME_H
  10. #include "Frame.h"
  11. #endif
  12.  
  13. #ifndef DEFINES_K
  14. #include "Defines.k"
  15. #endif
  16.  
  17. #ifndef BINDING_K
  18. #include "Binding.k"
  19. #endif
  20.  
  21. // ----- Framework Includes -----
  22. #ifndef FWABOUT_H
  23. #include "FWAbout.h"        //::FW_About()
  24. #endif
  25.  
  26. #ifndef SLMIXOS_H
  27. #include "SLMixOS.h"        // FW_GetMainScreenBounds
  28. #endif
  29.  
  30. //--- SOM library ------------------------------------------------
  31. #ifndef SOM_DevUniv_SFinance_xih
  32. #include "SFinance.xih"                // DevUniv_SFinance SOM library
  33. #endif
  34.  
  35. //==============================================================================
  36. #ifdef FW_BUILD_MAC
  37. #pragma segment Calc
  38. #endif
  39.  
  40. FW_DEFINE_AUTO(CCalcPart)
  41.  
  42. //==============================================================================
  43. CCalcPart::CCalcPart(ODPart* odPart)
  44.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  45.      fPresentation(NULL),
  46.       fLoanAmount(0),
  47.       fAnnualInterestPercent(0),
  48.       fLoanYears(0),
  49.       fMonthlyPayment(0),
  50.       fSOMFinanceCalc(NULL)
  51. {
  52. }
  53.  
  54. //--------------------------------------------------------------------------------
  55. CCalcPart::~CCalcPart()
  56. {
  57.     delete fSOMFinanceCalc;
  58. }
  59.  
  60. //--------------------------------------------------------------------------------
  61. void 
  62. CCalcPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)    // Override
  63. {
  64.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  65.     FW_CSelection* selection = NULL;
  66.     const ODType kMainPresentation = "Apple:Presentation:Calc";
  67.     fPresentation = this->RegisterPresentation(ev, kMainPresentation, true, selection);
  68.     fSOMFinanceCalc = new DevUniv_SFinance;
  69. }
  70.  
  71. //--------------------------------------------------------------------------------
  72. FW_CFrame* 
  73. CCalcPart::NewFrame(Environment* ev, ODFrame* odFrame,
  74.                     FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  75. {
  76.     FW_UNUSED(fromStorage);
  77.     return FW_NEW(CCalcFrame, (ev, odFrame, presentation, this));
  78. }
  79.  
  80. //--------------------------------------------------------------------------------
  81. FW_CContent* 
  82. CCalcPart::NewPartContent(Environment* ev)
  83. {
  84.     FW_UNUSED(ev);
  85.     return NULL;
  86. }
  87.  
  88. //--------------------------------------------------------------------------------
  89. FW_Handled 
  90. CCalcPart::DoAbout(Environment* ev)
  91. {
  92.     ::FW_About(ev, this, kAbout);
  93.     
  94.     return FW_kHandled;
  95. }
  96.  
  97. //-------------------------------------------------------------------
  98. CalcFloat 
  99. CCalcPart::MyComputePayment(Environment* ev)
  100. {
  101.     fMonthlyPayment = fSOMFinanceCalc->Payment(ev, fLoanAmount, 
  102.                                                 fAnnualInterestPercent,
  103.                                                 fLoanYears);
  104.     return fMonthlyPayment;
  105. }
  106.  
  107. //-------------------------------------------------------------------
  108. void 
  109. CCalcPart::MySetLoanAmount(CalcFloat borrowed)
  110. {
  111.     fLoanAmount = borrowed;
  112. }
  113.  
  114. //-------------------------------------------------------------------
  115. void 
  116. CCalcPart::MySetAnnualInterestPercent(CalcFloat interest)
  117. {
  118.     fAnnualInterestPercent = interest;
  119. }
  120.  
  121. //-------------------------------------------------------------------
  122. void 
  123. CCalcPart::MySetLoanYears(CalcFloat years)
  124. {
  125.     fLoanYears = years;
  126. }
  127.  
  128. //----------------------------------------------------------------------------------------
  129. FW_CWindow* 
  130. CCalcPart::NewDocumentWindow(Environment* ev)
  131. {    
  132.     FW_CRect screenBounds;
  133.     ::FW_GetMainScreenBounds(screenBounds);
  134.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  135.     
  136.     return new FW_CWindow(ev,
  137.                         this,
  138.                          FW_CPart::fgViewAsFrameToken,
  139.                         fPresentation,
  140.                         FW_CPoint(FW_IntToFixed(280), FW_IntToFixed(200)),
  141.                         screenBounds.TopLeft(),
  142.                         FW_kDocumentWindow);
  143. }
  144.